#!/usr/bin/perl # # Example of talking to instrument via SCPI-over-sockets # use IO::Socket; # Change to your instrument's name my $instrumentName = "xxxxxx"; # Get socket $sock = new IO::Socket::INET ( PeerAddr => $instrumentName, PeerPort => 5025, Proto => 'tcp', ); die "Socket Could not be created, Reason: $!\n" unless $sock; # Set freq print "Setting frequency...\n"; print $sock "freq 1 ghz\n"; # Wait for complete print "Waiting for source to settle...\n"; print $sock "*opc?\n"; my $response = <$sock>; chomp $response; # Remove newline from response if ($response ne "1") { die "Bad response to '*OPC?' from instrument!\n"; } # Send identification query print $sock "*IDN?\n"; $response = <$sock>; chomp $response; print "Instrument ID: $response\n";